//
//  CircleDetailReplyListrViewModel.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/3.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "CircleDetailReplyListrViewModel.h"
#import "CircleReplyDetailTableViewCell.h"
#import "CircleReplyDetailHeaderView.h"
#import "CommentBottomView.h"

@interface CircleDetailReplyListrViewModel ()<UITableViewDelegate, UITableViewDataSource>
{
    UITableView *selfTableView;
    UIView *selfView;
    CircleReplyDetailHeaderView *headerView;
    CommentBottomView *bottomView;
}

@end

@implementation CircleDetailReplyListrViewModel

- (instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView
{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {

        CGFloat hei = KScreenHeight - 64;
        if (iPhoneX) {
            hei = KScreenHeight - 88 - kHeightProportion_In_iPhoneTriploid(34) - kHeightProportion_In_iPhoneTriploid(36);
        }
        
        tableView.y = KScreenHeight;
        tableView.height = hei;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.sectionFooterHeight = 0;
        tableView.backgroundColor = [UIColor whiteColor];
        tableView.estimatedRowHeight = 44;
        tableView.rowHeight = UITableViewAutomaticDimension;
        selfTableView = tableView;
        [selfTableView registerClass:[CircleReplyDetailHeaderView class] forHeaderFooterViewReuseIdentifier:@"CircleReplyDetailHeaderView"];
        
        selfView = superView;
//        bottomView = [[CommentBottomView alloc] initWithInSuperView:superView];
        [self showReplyListView];
    }
    return self;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return kHeightProportion_In_iPhoneTriploid(48);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 9;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CircleReplyDetailTableViewCell *cell = [CircleReplyDetailTableViewCell cellWithTableView:tableView];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CircleReplyDetailHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"CircleReplyDetailHeaderView"];
    kWeakSelf(self);
    headerView.BlockDelete = ^(GLGWButton * _Nullable deleteBtn) {
        [weakself deleteView];
    };
    headerView.desStr = @"328条回复";
    return headerView;
}

- (void)showReplyListView
{
    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
    [window addSubview:selfTableView];
    [UIView animateWithDuration:0.7 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:3 options:UIViewAnimationOptionCurveEaseIn animations:^{
        self->selfTableView.y = 75;

    } completion:nil];
}

- (void)deleteView
{
    [UIView animateWithDuration:0.5 animations:^{
         self->selfTableView.y = KScreenHeight;
    } completion:^(BOOL finished) {
        [self->selfTableView removeFromSuperview];
    }];
}
//
//- (void)likeBtn:(GLGWButton *)btn
//{
//    if (self.BlockLike) {
//        self.BlockLike(btn);
//    }
//}
//
//- (void)allReplyBtn:(GLGWButton *)btn
//{
//    if (self.BlockAllReply) {
//        self.BlockAllReply(btn);
//    }
//}

@end
